
package model.test;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author FELIPE & NICOLAS
 */
public class FIBQ extends Question{
    
    
    private ArrayList<String> corrAns;      //arrayList containing the possible correct answers
    
    //class Constructor
    public FIBQ(String questionTxt,int marks,float penalty,ArrayList<String> corrAns, String imageFile){
        
        super(questionTxt,marks,penalty,imageFile);//superclass constructor
        this.type="FIBQ";//variable from superclass
        this.corrAns = corrAns;
        
    }
    
    
    ////constructor 2 (from a string readed from a txt file, which has been pased by the SUBSECTION constructor)
    public FIBQ(String inputString){
        super("empty",0,0,""); //trick, then modify it
        
        corrAns=new ArrayList<String>();
        
        String[] readResultQuestion = inputString.split("~"); //readResultQuestion is an array that represents each question, which contain the info about the question
        
        //data about the question
        this.type = readResultQuestion[0];              //it has to be MCQ
        this.questionTxt = readResultQuestion[1];
        this.marks =Integer.parseInt(readResultQuestion[2]);
        this.penalty =Float.parseFloat(readResultQuestion[3]);
        this.imageFile=readResultQuestion[4];
        
        //get the possible correct answers
        String[] readResultCorrAns = readResultQuestion[5].split("&"); //split into correct answers
                       
        for (int l=0;l<readResultCorrAns.length;l++){
           corrAns.add(readResultCorrAns[l]);
        }
        
    }
    
    
    
    //toString method
    public String toString(){
        return this.type + "~" +this.questionTxt+ "~" + this.marks +"~"+ this.penalty +"~"+ this.imageFile +"~" + this.toStringCorrAns();
    }
    
    
    //toString method to convert correct Answers
    public String toStringCorrAns(){
        
        Iterator<String> iter =corrAns.iterator();
        String result=iter.next();
        
        while ( iter.hasNext() ){
            result=result+"&"+iter.next();
        }
        
        return result;
    }
    
    
    
    //GETTERS AND SETTERS
    public ArrayList<String> getCorrAns() {
        return corrAns;
    }

    public void setCorrAns(ArrayList<String> corrAns) {
        this.corrAns = corrAns;
    }

    public int getMarks() {
        return marks;
    }

    public void setMarks(int marks) {
        this.marks = marks;
    }
    
    public float getPenalty() {
        return penalty;
    }

    public void setPenalty(int penalty) {
        this.penalty = penalty;
    }

    public String getQuestionTxt() {
        return questionTxt;
    }

    public void setQuestionTxt(String questionTxt) {
        this.questionTxt = questionTxt;
    }

    public String getType() {
        return type;
    }
    
    public void setImageFile(String imageFile) {
        this.imageFile = imageFile;
    }

    public String getImageFile() {
        return imageFile;
    }
    //you cannot change the type of question
    //public void setType(String type) {
      //  this.type = type;
    //}
    
    
    
    
    

    //FOR TESTING PURPOSE
    public static void main(String[] args) {
		
         //Create a FIBQ and show it
         ArrayList<String> corrAnswers = new ArrayList<String>();
         corrAnswers.add("Dont");
         corrAnswers.add("Don't");
         corrAnswers.add("Do not");
         FIBQ temp = new FIBQ("What is____?",10,0,corrAnswers,"carrot.jpg");
         FIBQ temp2 = new FIBQ("FIBQ~What is____?~10~0.0~carrot.jpg~Dont&Don't&Do not");
         System.out.println(temp);
         System.out.println(temp2.imageFile);


    }
    
}
